package com.tjwx.controller;

import com.tjwx.service.RegisterService;
import com.tjwx.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Controller
@RequestMapping(value = "/user")
public class UserController {
    private final static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    RegisterService registerService;
    @Autowired
    UserService userService;

    /**
     * 用户注册
     * @return
     */
    @RequestMapping(method = {RequestMethod.OPTIONS, RequestMethod.POST},value = "/register",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Object register(@RequestBody Map user) {
        return registerService.addUser(user);
    }

    /**
     * 用户登录
     * @return
     */
    @RequestMapping(method = {RequestMethod.OPTIONS, RequestMethod.POST},value = "/login")
    @ResponseBody
    public Object showLog(HttpServletRequest request, HttpServletResponse response,
                          @RequestBody Map user) {
        return userService.login(user,response);
    }

}
